package common.packets;

/**
 * Messege to another user
 * @author  mickek
 */
public class MessagePacket extends Packet {

	public static final String PREFIX = "message";
	public static final int MESSAGE_HEADER = 3;
	private String sender;
	private String message;
	private String[] reciepients;

	public MessagePacket(String _sender, String _message, String[] _reciepients) {

		sender = _sender;
		message = _message;
		reciepients = _reciepients;
	}
	
	/**
	 * @return
	 * @uml.property  name="message"
	 */
	public String getMessage(){
		return message;
	}

	public String[] getReciepients() {
		return reciepients;
	}

	public void setReciepients(String[] reciepients) {
		this.reciepients = reciepients;
	}

	@Override
	public byte[] serialize() {
		// TODO base64 encoding na stringach
		StringBuffer sb = new StringBuffer();
		for( String cc : reciepients ) sb.append(cc).append(Packet.DELIMITER);
		return (PREFIX + Packet.DELIMITER + sender + Packet.DELIMITER + message + Packet.DELIMITER + sb.toString() + Packet.NEW_LINE).getBytes();	
	}

	@Override
	public String toString() {
		return PREFIX;
	}

	public String getSenderUserName() {
		return sender;
	}

	public void setSenderUserName(String sender) {
		this.sender = sender;
	}

}
